<?php

namespace Apps\Common\Libs;

/**
 * 图片地址处理
 * @package Apps\Common\Libs
 */
class PicUrl
{
    private static function getHttpBase($type, $di) {
        $httpBase = $di->get('appConfig')->aliyun->oss->http_base;
        return $httpBase;
    }
    /**
     * 问答
     * @param $url
     * @param $di
     * @return string|array
     */
    public static function Question($url, $di)
    {
        $httpBase = self::getHttpBase('question', $di);
        if(is_string($url)) {
            return $httpBase . $url;
        }
        if(is_array($url)) {
            $arr = [];
            foreach($url as $u) {
                $arr[] = $httpBase . $u;
            }
            return $arr;
        }
    }

    /**
     * 美容院封面
     * @param $url
     * @param $di
     * @return string
     */
    public static function BeautyParlorCover($url, $di)
    {
        $httpBase = self::getHttpBase('beauty_parlor_cover', $di);
        return $httpBase . $url;
    }
    
	/**
     * 美粒宝典封面
     * @param $url
     * @param $di
     * @return string
     */
    public static function BeautyCanonCover($url, $di)
    {
        $httpBase = self::getHttpBase('bp_cover', $di);
        return $httpBase . $url;
    }

    /**
     * 美容院图片
     * @param $url
     * @param $di
     * @return array|string
     */
    public static function BeautyParlorPic($url, $di)
    {
        $httpBase = self::getHttpBase('beauty_parlor_pics', $di);
        if(is_string($url)) {
            return $httpBase . $url;
        }
        if(is_array($url)) {
            $arr = [];
            foreach($url as $u) {
                $arr[] = $httpBase . $u;
            }
            return $arr;
        }
    }
    /**
     * 广告封面
     * @date: 2016年1月7日 
     * @author: chenxiaolin
     */
    public static function AdvertisementPic($url, $di)
    {
        $httpBase = self::getHttpBase('advertisement_cover', $di);
        if(is_string($url)) {
            return $httpBase . $url;
        }
        if(is_array($url)) {
            $arr = [];
            foreach($url as $u) {
                $arr[] = $httpBase . $u;
            }
            return $arr;
        }
    }

    /**
     * 用户头像
     * @param $url
     * @param $di
     * @return string
     */
    public static function UserCover($url, $di)
    {
        if (preg_match("/^http:\/\//", $url)) {
            return $url;
        }
        $httpBase = self::getHttpBase('user_cover', $di);
        return $httpBase . $url;
    }

    /**
     * 美容院评论
     * @param $url
     * @param $di
     * @return string
     */
    public static function BeautyParlorComment($url, $di)
    {
        $httpBase = self::getHttpBase('beauty_parlor_comment', $di);
        if(is_string($url)) {
            return $httpBase . $url;
        }
        if(is_array($url)) {
            $arr = [];
            foreach($url as $u) {
                $arr[] = $httpBase . $u;
            }
            return $arr;
        }
    }

    /**
     * 活动封面
     * @param $url
     * @param $di
     * @return string
     */
    public static function ActivityCover($url, $di)
    {
        $httpBase = self::getHttpBase('activity_cover', $di);
        return $httpBase . $url;
    }

    /**
     * 活动内容图片
     * @param $url
     * @param $di
     * @return string
     */
    public static function ActivityPics($url, $di)
    {
        $httpBase = self::getHttpBase('activity_pics', $di);
        return $httpBase . $url;
    }
    
    /**
     * 美粒互动图片
     * @date: 2016年4月21日 
     * @author: chenxiaolin
     */
    public static function InteractivePics($url, $di)
    {
        $httpBase = self::getHttpBase('beauty_parlor_interactive', $di);
        return $httpBase . $url;
    }
    
    /**
     * 图片默认URL
     * @param $url
     * @param $di
     * @return string
     */
    public static function DefaultPics($url, $di)
    {
        $httpBase = self::getHttpBase('activity_cover', $di);
        return $httpBase . $url;
    }
}